package com.example.product.controller;

import com.example.product.entity.Product;
import com.example.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhuyaotong
 * @date 2021/6/2
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Product findById(@PathVariable Long id) {
        return productService.findById(id);
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    public String save(@RequestBody Product product) {
        productService.save(product);
        return "保存成功！";
    }

    @RequestMapping(value = "", method = RequestMethod.PUT)
    public String update(@RequestBody Product product) {
        productService.save(product);
        return "更新成功！";
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String update(@PathVariable Long id) {
        productService.delete(id);
        return "删除成功！";
    }

}
